package com.mall.admin.service;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.commons.utils.PageResult;
import com.mall.domain.OmsCompanyAddress;
import com.mall.domain.OmsOrderReturnApply;
import com.mall.dto.OrderReturnDto;
import com.mall.dto.ReturnApplyDto;
import com.mall.interface1.api.OmsOrderReturnApplyApi;
import com.mall.vo.ReturnVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OmsOrderReturnApplyService {

    @DubboReference
    private OmsOrderReturnApplyApi omsOrderReturnApplyApi;

    //批量删除退货申请
    public void deleteReturn(List<Long> ids) {
        omsOrderReturnApplyApi.deleteReturn(ids);
    }

    //分页查询退货申请
    public PageResult list(ReturnApplyDto dto) {
        List<OmsOrderReturnApply> oorList = omsOrderReturnApplyApi.list(dto);
        Integer count = omsOrderReturnApplyApi.count(dto);
        return new PageResult(dto.getPageNum(),dto.getPageSize(),count,oorList);
    }

    //修改退货申请状态
    public void updateStatus(Long id, OrderReturnDto dto) {
        OmsOrderReturnApply omsOrderReturnApply = new OmsOrderReturnApply();
        BeanUtil.copyProperties(dto,omsOrderReturnApply,"id");
        omsOrderReturnApply.setOrderId(dto.getId());
        omsOrderReturnApply.setId(id);
        omsOrderReturnApplyApi.updateStatus(id,omsOrderReturnApply);
    }

    //获取退货申请详情
    public ReturnVo findReturn(Long id) {
        ReturnVo vo = new ReturnVo();
        OmsOrderReturnApply omsOrderReturnApply = omsOrderReturnApplyApi.findReturnById(id);
        BeanUtil.copyProperties(omsOrderReturnApply,vo);
        //根据地址id获取地址
        OmsCompanyAddress omsCompanyAddress = omsOrderReturnApplyApi.findAddressById(omsOrderReturnApply.getCompanyAddressId());
        vo.setCompanyAddress(omsCompanyAddress);
        return vo;
    }
}
